home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / AfterDark / TwilightZone ƒ / source / patches.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  1.2 KB  |  65 lines  |  [TEXT/KAHL]

  1. /* patches required for after dark to run */
  2.  
  3. #include <Traps.h>
  4. #include "patches.h"
  5.  
  6. #define    kOSEIdentifier    0x61596d6d
  7.  
  8. typedef struct OSEData {
  9.     OSType    signature;
  10.     long    fill[2];
  11.     short    version;
  12. } OSEData;
  13.  
  14. long gGetOSEventLink;
  15. OSEData gADData;
  16.  
  17. void InstallPatches(void)
  18. {
  19.     gADData.signature = 'ADr2';
  20.     gADData.version = 0x200;
  21.     gADData.fill[0] = gADData.fill[1] = 0;
  22.     
  23.     gGetOSEventLink = NGetTrapAddress(_GetOSEvent,OSTrap);
  24.     gGetOSEventLink = (long) StripAddress((Ptr)gGetOSEventLink);
  25.     NSetTrapAddress((long)MyGetOSEvent,_GetOSEvent,OSTrap);
  26. }
  27.  
  28.  
  29. void RemovePatches(void)
  30. {
  31.     NSetTrapAddress((long)gGetOSEventLink,_GetOSEvent,OSTrap);
  32. }
  33.  
  34.  
  35. /* GetOSEventPatch */
  36.  
  37. pascal void MyGetOSEvent(void)
  38. {
  39.     asm {
  40.         movem.l    a2-a3,-(sp)                ; save regs
  41.         move.l    a5,a2                    ; get app a5
  42.         move.l    CurrentA5,a5    
  43.         move.l    gGetOSEventLink,a1        ; get link addr
  44.         move.l    a2,a5                    ; restore non-app a5
  45.         
  46.         tst.w    d0
  47.         bne.s    @exit
  48.         cmpi.l    #kOSEIdentifier,2(a0)
  49.         bne.s    @exit
  50.                 
  51.         jsr        (a1)                    ; tail patch (yuk)
  52.         lea        gADData,a3
  53.         move.l    a3,10(a0)
  54.         move.l    (a3),2(a0)
  55.         move.w    #0x180,14(a0)
  56.         
  57.         move.l    #-1,d0
  58.         movem.l    (sp)+,a2-a3                ; restore regs
  59.         rts
  60.         
  61. @exit    movem.l    (sp)+,a2-a3                ; restore regs
  62.         jmp        (a1)                    ; jump to link
  63.     }
  64. }
  65.